package MainTest;

/**
 * Created by zhaott on 2018/1/15.
 */
import java.sql.*;

public class DBHelper {

    public static void main(String[] a){
        DBHelper d=new DBHelper("select count(*) from  "+tablename);
        String sql="insert into "+tablename+" (xm,xb,jtgx) values('张三','男','父亲') ";
        d.insert(sql);
    }

   /* */public static final String url = "jdbc:mysql://10.10.50.83:3306/test4?characterEncoding=UTF-8";
    public static final String name = "com.mysql.jdbc.Driver";
    public static final String user = "root";
    public static final String password = "root";
    public static final String tablename = "zdshbzryexcel";

   /* public static final String url = "jdbc:mysql://localhost:3306/information_schema";
    public static final String name = "com.mysql.jdbc.Driver";
    public static final String user = "root";
    public static final String password = "";*/

    public Connection conn = null;
    public PreparedStatement pst = null;

    public DBHelper(String sql) {
        /*try {
            Class.forName(name);//指定连接类型
            conn = DriverManager.getConnection(url, user, password);//获取连接
            pst = conn.prepareStatement(sql);//准备执行语句
            ResultSet set=pst.executeQuery();
            System.out.println(set.next());
        } catch (Exception e) {
            e.printStackTrace();
        }*/
    }

    public void insert(String sql) {
        try {
            Class.forName(name);//指定连接类型
            conn = DriverManager.getConnection(url, user, password);//获取连接
            pst = conn.prepareStatement(sql);//准备执行语句
            boolean insert=pst.execute();
            System.out.println(insert);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void close() {
        try {
            this.conn.close();
            this.pst.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}